package com.fairytask.ui.item
{
	import com.fairytask.data.ViewObject;
	import com.fairytask.engine.components.clip.Clip;
	import com.fairytask.engine.define.ResConfig;
	import com.fairytask.managers.ResManager;
	import com.fairytask.managers.TipsManage;
	import com.fairytask.resource.StaticIni;
	import com.fairytask.tools.SystemTime;
	import com.greensock.TweenMax;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	/**
	 *Buff 显示效果的子项 
	 */
	public class BuffItem extends Sprite
	{
		private var _icon		:Clip	=	new Clip(true,reSizeHead,null);
		private var _clip		:MovieClip;				//显示的背景
		private var _data		:ViewObject;			//视图的数据
		private var _tipsStr	:String	=	"";			//用于显示tip的文字
		private var _type		:int;					//效果的类型
		
		//时间的显示
		private var _timeStr	:String;				//显示时间的文本
		private var _startTime	:Number;				//开始时间
		private var _lifeTime	:Number	=	0;				//生命周期
		private var _nowTime	:Number;				//现在的时间
		private var _date		:Date;					//日期
		private var _buffId	:int;
		
		
		public function BuffItem()
		{
			super();
			init();
			initEvent();
		}
		
		//初始化的显示
		private function init():void
		{
			_clip			=	ResManager.newResClass("CustSkin_017") as MovieClip;
			_clip.width		=	24;
			_clip.height	=	24;
			_icon.x			=	2;
			_icon.y			=	2;
			//设置大小后添加到容器中去
			addChild(_clip);
			addChild(_icon);
		}
		
		/**
		 *  初始化事件 
		 */
		private function initEvent():void
		{
			addEventListener(MouseEvent.ROLL_OVER, showTips);
			addEventListener(MouseEvent.ROLL_OUT, hideTips);
		}
		
		

		
		/**
		 * 加载完成，设置头像图片大小
		 * 
		 */		
		private function reSizeHead(val:Clip):void
		{
			val.width = 18;
			val.height= 18;
		}
		
		/**
		 * 显示 tips 
		 * @param evt
		 * 
		 */
		private function showTips(evt:MouseEvent):void
		{
			TipsManage.showTips(tipsStr);
		}
		
		/**
		 * 隐藏 tips 
		 * @param evt
		 * 
		 */
		private function hideTips(evt:MouseEvent):void
		{
			TipsManage.hideTips();
		}
		
		private function get tipsStr():String
		{
			if(_type==1)
			{
				var str:String		=	_data.GetProperties("DescribeID");
				_startTime	=	_data.GetProperties("StartTime");
				//_lifeTime	=	_data.GetProperties("LifeTime");
				//时间类型
				var timeType:int = int(StaticIni.getIniVar(_buffId,"TimeType"));
				//剩余时间秒
				var leaveTime : Number = SystemTime.getLeftTime(_startTime*1000,_lifeTime*1000*60);
				//合适显示时间
				var timeStr	: String = SystemTime.retrieveFormatByInt(leaveTime);
				_tipsStr	=	StaticIni.getSwfLangStrVar(str,[timeStr]);
			}
			else if(_type==0)
			{
				_tipsStr	=	StaticIni.getSwfLangStr(str);
			}
			return _tipsStr;
			//return timeStr;
		}
		
		
		public function get data():ViewObject
		{
			return _data;
		}
		
		public function set data(value:ViewObject):void
		{
			_data = value;
			_startTime	=	value.GetProperties("StartTime");
			_lifeTime	=	value.GetProperties("LifeTime");
			_buffId	=	value.GetProperties("ConfigID");
			_type	=	value.GetProperties("StatusType");
			_icon.source	=	ResConfig.buffPath + StaticIni.getIniVar(_buffId,"Icon") + ".png";
		}
		
		
		public function set lifeTime(val:int):void
		{
			_lifeTime = val;
		}
		
		/**
		 *实现特效 
		 * 
		 */		
		public function addFilter():void
		{
			TweenMax.to(_icon,3, {glowFilter:{color:0xFFFFFF, alpha:0.7, blurX:30, blurY:30, strength:2, quality:1},repeat:1,yoyo:true,startAt:{glowFilter:{color:0xFFFFFF, alpha:0.2, blurX:0, blurY:0, strength:1, quality:1}},onComplete:function():void 
			{
				_icon.filters = null;
			}});
		}
		public function get bufferID():int
		{
			return _buffId;
		}
		
	}
}